From 37b1acfa0ca2a8984fdd88728ec048400ea6df86 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Sat, 27 Jan 2007 21:37:49 +0000 Subject: [PATCH] Add option "DATATYPE", which can be WAYPOINT, ROUTE or TRACK, to xcsv format. --- csv_util.c | 31 +++++++++++++++++++++++++++---- csv_util.h | 2 ++ vecs.c | 12 +++++++++++- xcsv.c | 24 ++++++++++++++++++++++-- 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/csv_util.c b/csv_util.c index ceb4c5f8a..f2e52c84b 100644 --- a/csv_util.c +++ b/csv_util.c @@ -1005,7 +1005,18 @@ xcsv_data_read(void) queue *elem, *tmp; field_map_t *fmp; ogue_t *ogp; + route_head *rte = NULL; + route_head *trk = NULL; + if (xcsv_file.datatype == trkdata) { + trk = route_head_alloc(); + track_add_head(trk); + } else + if (xcsv_file.datatype == rtedata) { + rte = route_head_alloc(); + route_add_head(rte); + } + while ((buff = gbfgetstr(xcsv_file.xcsvfp))) { linecount++; /* Whack trailing space; leading space may matter if our field sep @@ -1066,7 +1077,16 @@ xcsv_data_read(void) GPS_Math_Known_Datum_To_WGS84_M(wpt_tmp->latitude, wpt_tmp->longitude, 0.0, &wpt_tmp->latitude, &wpt_tmp->longitude, &alt, xcsv_file.gps_datum); } - waypt_add(wpt_tmp); + switch(xcsv_file.datatype) { + case 0: + case wptdata: + waypt_add(wpt_tmp); break; + case trkdata: + track_add_wpt(trk, wpt_tmp); break; + case rtedata: + route_add_wpt(rte, wpt_tmp); break; + default: ; + } } } @@ -1528,9 +1548,12 @@ xcsv_data_write(void) gbfprintf(xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter); } - waypt_disp_all(xcsv_waypt_pr); - route_disp_all(xcsv_resetpathlen,xcsv_noop,xcsv_waypt_pr); - track_disp_all(xcsv_resetpathlen,xcsv_noop,xcsv_waypt_pr); + if ((xcsv_file.datatype == 0) || (xcsv_file.datatype == wptdata)) + waypt_disp_all(xcsv_waypt_pr); + if ((xcsv_file.datatype == 0) || (xcsv_file.datatype == rtedata)) + route_disp_all(xcsv_resetpathlen,xcsv_noop,xcsv_waypt_pr); + if ((xcsv_file.datatype == 0) || (xcsv_file.datatype == trkdata)) + track_disp_all(xcsv_resetpathlen,xcsv_noop,xcsv_waypt_pr); /* output epilogue lines, if any. */ QUEUE_FOR_EACH(&xcsv_file.epilogue, elem, tmp) { diff --git a/csv_util.h b/csv_util.h index cfb0eaaa2..e8659a82b 100644 --- a/csv_util.h +++ b/csv_util.h @@ -133,6 +133,8 @@ typedef struct { ff_type type; /* format type for GUI wrappers. */ int gps_datum; /* result of GPS_Lookup_Datum_Index */ + gpsdata_type datatype; /* can be wptdata, rtedata or trkdata */ + /* ... or ZERO to keep the old behaviour */ } xcsv_file_t; diff --git a/vecs.c b/vecs.c index 80dac5122..45c2689b9 100644 --- a/vecs.c +++ b/vecs.c @@ -976,7 +976,17 @@ sort_and_unify_vecs(int *ctp) */ svp[i]->vec->args++; } - + memset(&svp[i]->vec->cap, 0, sizeof(svp[i]->vec->cap)); + switch(xcsv_file.datatype) { + case 0: + case wptdata: + svp[i]->vec->cap[ff_cap_rw_wpt] = ff_cap_read | ff_cap_write; break; + case trkdata: + svp[i]->vec->cap[ff_cap_rw_trk] = ff_cap_read | ff_cap_write; break; + case rtedata: + svp[i]->vec->cap[ff_cap_rw_rte] = ff_cap_read | ff_cap_write; break; + default: ; + } svp[i]->desc = xcsv_file.description; svp[i]->parent = "xcsv"; } diff --git a/xcsv.c b/xcsv.c index 87cb0ead5..c3677c923 100644 --- a/xcsv.c +++ b/xcsv.c @@ -338,6 +338,24 @@ xcsv_parse_style_line(const char *sbuff) is_fatal(xcsv_file.gps_datum < 0, MYNAME ": datum \"%s\" is not supported.", p); xfree(p); } else + + if (ISSTOKEN(sbuff, "DATATYPE")) { + p = csv_stringtrim(&sbuff[8], "\"", 1); + if (case_ignore_strcmp(p, "TRACK") == 0) { + xcsv_file.datatype = trkdata; + } + else if (case_ignore_strcmp(p, "ROUTE") == 0) { + xcsv_file.datatype = rtedata; + } + else if (case_ignore_strcmp(p, "WAYPOINT") == 0) { + xcsv_file.datatype = wptdata; + } + else { + fatal(MYNAME ": Unknown data type \"%s\"!\n", p); + } + xfree(p); + + } else if (ISSTOKEN(sbuff, "IFIELD")) { key = val = pfc = NULL; @@ -521,8 +539,10 @@ xcsv_rd_init(const char *fname) xcsv_read_style(styleopt); } - if (global_opts.masked_objective & (TRKDATAMASK|RTEDATAMASK)) { - warning(MYNAME " attempt to read %s as a track or route, but this module only supports waypoints on read. Reading as waypoints instead.\n", fname); + if ((xcsv_file.datatype == 0) || (xcsv_file.datatype == wptdata)) { + if (global_opts.masked_objective & (TRKDATAMASK|RTEDATAMASK)) { + warning(MYNAME " attempt to read %s as a track or route, but this format only supports waypoints on read. Reading as waypoints instead.\n", fname); + } } xcsv_file.xcsvfp = gbfopen(fname, "r", MYNAME); -- 2.30.2